<?php
class Admin_CommentController extends Zend_Controller_Action {
	public function init() {
		$layoutPath = APPLICATION_PATH . '/templates/admin';
		$options = array (
				'layout' => 'index',
				'layoutPath' => $layoutPath 
		);
		Zend_Layout::startMvc ( $options );
	}
	public function indexAction() {
		list ( $this->view->Pager, $this->view->Comments ) = Comment::getAll ();
	}
	public function createAction() {
		$requests = $this->getRequest ()->getParams ();
		if ($this->getRequest ()->isPost ()) {
			try {
				$Comment = new Comment ();
				$Comment->merge ( $requests );
				$Comment->created_date = date ( 'Y-m-d H:i:s', time () );
				$Comment->ip=$_SERVER ['REMOTE_ADDR'];
				$User = new Zend_Session_Namespace ( 'Login' );
				$Comment->save ();
				$this->view->Message = 'Create comment successfull';
			} catch ( Exception $e ) {
				print_r ( $e->getMessage () );
				die ();
			}
		}
	}
	public function editAction() {
		$requests = $this->getRequest ()->getParams ();
	
		$Comment = Comment::getById ( $requests ['id'] );
	
		if ($Comment) {
				
			$this->view->Comment = $Comment;
			if ($this->getRequest ()->isPost ()) {
				try {
					$Comment->merge ( $requests );
					$Comment->save ();
					$this->view->Message = 'Update comment successfull';
				} catch ( Exception $e ) {
					print_r ( $e->getMessage () );
					die ();
				}
			}
		} else {
			$this->_redirect ( '/admin/comment' );
		}
	}
}

